from selenium.webdriver.common.by import By
import time
from yuekaolianxi.po.Base.Base import Base
class Page(Base):

    # 请登录
    denglu=(By.XPATH,'/html/body/div[2]/div/div[1]/div/a[1]')
    def denglu_loc(self):
        self.click(self.denglu)
    # 输入用户名
    name=(By.XPATH,'//*[@id="userName"]')
    def name_loc(self):
        self.send_keys(self.name,'15336710135')
    # 输入密码
    password=(By.XPATH,'//*[@id="password"]')
    def password_loc(self):
        self.send_keys(self.password,'002816Hj')
    # 点击登录
    dengruanniu=(By.XPATH,'//*[@id="save"]')
    def dengruanniu_loc(self):
        self.click(self.dengruanniu)
    # 点击确定
    qd=(By.XPATH,'//*[@id="bindSub"]')
    def qd_loc(self):
        self.click(self.qd)
    # 搜索框
    ssk=(By.XPATH,'//*[@id="wd"]')
    def ssk_loc(self):
        self.send_keys(self.ssk,'茅台')
    #     点击商品
    sp=(By.XPATH,'/html/body/div[6]/div/div[2]/div[5]/ul/li[1]/div[2]/div[1]/a/img')
    def sp_loc(self):
        self.click(self.sp)
    # 添加购物车
    tj=(By.XPATH,'//a[@id="addToCartForDetail" and @class="buyBtn buyBtn-cart"]')
    def tj_loc(self):
        self.click(self.tj)
    #    查看购物车
    gwc=(By.XPATH,'//a[starts-with(@class,"u-buy-go")]')
    def gwc_loc(self):
        self.click(self.gwc)


    def jiuxian_login(self):
        try:
            self.goto('https://www.jiuxian.com/')
            time.sleep(2)
            self.denglu_loc()
            self.name_loc()
            self.password_loc()
            time.sleep(10)
            self.dengruanniu_loc()
            self.qd_loc()
            time.sleep(2)
            self.ssk_loc()
            self.hc(self.ssk)
            self.sp_loc()
            time.sleep(2)
            self.qh()
            self.tj_loc()
            time.sleep(2)
            self.gwc_loc()
        except Exception as e:
            self.jt()
